<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>
    <link rel="stylesheet" href="../../css/print.css"/>
    <style>
        #treament-plan-wrap h2, #treament-plan-wrap h3 {
            font-size: 14px;
        }
    </style>

</head>
<body class="print-wrap">
<button id="print-btn" class="layui-btn layui-btn-xs ares-d-print-none ares-position-absolute ares-absolute-tr-offset">打印</button>
<h3>基本信息</h3>
<div class="ares-mb emr-info"></div>
<h3>训练方案 <span id="item-type-name"></span></h3>
<div id="treament-plan-wrap" class="ares-px"></div>

<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
    var init;
    layui.use(['dateFilters', 'commonServices', 'mandyServices', 'qs' ,'printArea'], function (dateFilters, commonServices, mandyServices, qs, printArea) {
        var emrId, is_referral_history, itemType;

        init = function () {
            var localHash = location.hash,
                queryStr = localHash.split('?')[1],
                routerParams = top.layui.routers.params,
                routerQuery = queryStr ? qs.parse(queryStr) : {};
            console.log(localHash, queryStr, routerParams, routerQuery)
            emrId = routerParams.emrId;
            is_referral_history = routerQuery.isReferralHistory;
            itemType = routerQuery.itemType;
            $('#item-type-name').text('(' + itemType + ')');
            getPatientInfo();
            getTrainingPlan(1, 1000);
        }
        init();
        /**
         * @author: ares
         * @date: 2021/3/30 11:51
         * @description: 打印
         */
        $('#print-btn').on('click', function () {
            $('.print-wrap').printArea();
        })

        /**
         * @author: ares
         * @date: 2021/3/30 12:42
         * @description: 分页查询
         * @param{number} page
         * @param{number} pageSize
         */
        function getTrainingPlan(page, pageSize) {
            mandyServices.mandy_get_emr_group_training_plan(emrId, is_referral_history, itemType, page, pageSize).then(function (res) {
                var data = res.data,
                    list = data.list || [];
                if (data.is_private == "0") {
                    console.log("历史数据",data)
                } else if (data.is_private == "1") {
                    buildTreatHistoryPad(list);
                }
            });
        }

        /**
         * @author: ares
         * @date: 2021/3/30 14:07
         * @description: 构建训练计划结构(数据来自治疗师端)
         */
        function buildTreatHistoryPad(list) {
            var $wrap = $('#treament-plan-wrap'),
                $fragment = $(document.createDocumentFragment());
            $.each(list, function (index, item) {
                var plan = JSON.parse(item.plan),
                    result = plan.result;
                $fragment.append('<div class="plan-item ares-mb ares-border-bottom">' +
                    '<b>方案' + (++index) + '</b>' +
                    '<div class="plan-item-result ares-px">' + result + '</div>' +
                    '<div class="plan-item-therapist">' +
                    '<b class="ares-mr-lg">创建者: ' + item.creator.name + '</b>' +
                    '<b>创建时间: ' + dateFilters.dateTimeFormat(item.createTime) + '</b>' +
                    '</div>' +
                    '</div>')
            })
            $wrap.empty().append($fragment);
        }

        /**
         * @author: ares
         * @date: 2021/3/10 10:49
         * @description: 获取患者基本信息
         */
        function getPatientInfo() {
            commonServices.getEmrInfoService(emrId, null, null, $('.emr-info'))
        }
    })
</script>
</body>
</html>
